/**
 * Copyright (c) 2004-2015 All Rights Reserved.
 */
package com.zbest.zpay.cif.action;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Service;

import com.zbest.common.lang.util.RandomCharsUtils;
import com.zbest.zpay.shared.process.BaseAction;
import com.zbest.zpay.shared.process.ProcessResult;

/**
 * @author huwenfei
 * @version $Id: RegisterAction.java, v0.1 2015年12月5日 下午6:42:25 huwenfei Exp $
 */
@Service("registerAction")
public class RegisterAction extends BaseAction {

    /**
     * @see com.duodian.market.biz.shared.process.BaseAction#perform(com.duodian.market.common.model.ProcessResult)
     */
    @Override
    public void perform(ProcessResult processResponse) {/*
        RegisterForm registerForm = (RegisterForm) getValue(RegisterForm.class.getSimpleName());
        Merchant merchant = merchantRepository.getByMobileNo(registerForm.getMobileNo());
        if (merchant != null) {
            throw new MarketException(MarketBizCodeEnum.MOBILE_REGISTERED);
        }
        MerchantWechat merchantWechatTmp = merchantWechatRepository.getByTicketTmp(registerForm
            .getTicket());
        if (merchantWechatTmp != null) {
            throw new MarketException(MarketBizCodeEnum.MOBILE_REGISTERED);
        }
        *//** 校验动态验证码是否一致 *//*
        String dynamicCode = registerForm.getDynamicCode();
        String msgCode = MsgTplConstant.GEN_REGISTER_AUTH_CODE;
        String ticket = registerForm.getTicket();
        Map<String, Object> objectMap = new HashMap<String, Object>();
        boolean isVerify = msgTemplateManager.verifyDynamicCodeByWeixin(dynamicCode, msgCode,
            ticket, objectMap);
        if (isVerify) {
            String merchantId = sequenceRepository.genMerchantId();
            String openid = (String) objectMap.get(WeixinMessageField.FIELD_OPENID);
            String authorizerAppid = (String) objectMap
                .get(WeixinMessageField.FIELD_AUTHORIZER_APPID);
            MerchantWechat merchantWechat = new MerchantWechat();
            merchantWechat.setAuthorizerAppId(authorizerAppid);
            merchantWechat.setOpenId(openid);
            merchantWechat.setMerchantId(merchantId);
            merchantWechat.setTicketTmp(ticket);
            merchantWechatRepository.store(merchantWechat);

            String salt = RandomCharsUtils.randomChars(4);
            String loginPwd = DigestUtils.md5Hex(registerForm.getPassword() + salt);
            Merchant regMerchant = new Merchant();
            regMerchant.setMerchantId(merchantId);
            regMerchant.setMobileNo(registerForm.getMobileNo());
            regMerchant.setMerchantName(registerForm.getMerchantName());
            regMerchant.setLoginPassword(loginPwd);
            regMerchant.setLoginPasswordSalt(salt);
            regMerchant.setStatus("Y");
            regMerchant.setInvitor(registerForm.getInvitor());

            merchantRepository.store(regMerchant);
            processResponse.getResultObject().put(ContextField.KEY_MERCHANT, regMerchant);
        } else {
            throw new MarketException(MarketBizCodeEnum.WEIXIN_VERIFYCODE_ERROR);
        }
    */}
}
